import time
f1 = open('m1_sorted.txt','r')
f2 = open('m2_reverse.txt','r')
f3 = open('m3_shuffle.txt','r')
files=[f1,f2,f3]
s = []
def f1(f):
    s = []
    for i in range(5000-1):
        x = f.readline()
        s.append(int(x[0:len(x)-1]))
    s.append(int(f.readline()))
    return s

def f2(a) :
    a=[]
    n=len(a)
    sw=False
    for i in range(n-1):
        for j in range(n-i-1):
            if a[j] >a [j+1]:
                a[j],a[j+1]=a[j+1],a[j]
                sw=True

        if sw==False:
            return
    return
for i in range(0,3):
    mas=f1(files[i])
    start =time.time()
    f2(mas)
    print(mas)
    finish=time.time()
    print((finish-start)*1000)

